//
//  HomeListLogic.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/1/3.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "HomeListLogic.h"
#import "UserListInfo.h"
@implementation HomeListLogic

- (instancetype)init
{
    self = [super init];
    if (self) {
        _page = 0;
        _dataArray = [NSMutableArray array];
    }
    return self;
}

-(void)loadData
{
    if (_page == 0) {
        [_dataArray removeAllObjects];
    }
    
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"recommended_api" A:@"recommend_user"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@(_page) forKey:@"page"];
    
    [CYNET POSTv3:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if (_page == 1) {
            [_dataArray removeAllObjects];
        }
        NSArray *list = [NSArray modelArrayWithClass:[UserListInfo class] json:[responseObject valueForKey:@"data"]];
        [_dataArray addObjectsFromArray:list];
        
        self.online_emcee_count = [responseObject valueForKey:@"online_emcee_count"];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error, NSInteger code) {
        [[HUDHelper sharedInstance] tipMessage:error];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } hasCache:YES];
}

-(void)getShuffing
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"recommended_api" A:@"shuffling"];
    //    参数名    必选    类型    说明
    //    shuffling    是    string    1是推荐轮播图 2消息轮播图
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@"1" forKey:@"shuffling"];
    
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        _shuffling = [NSArray modelArrayWithClass:[ShufflingModel class] json:responseObject];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestShuffingCompleted:)]) {
            [self.delegagte requestShuffingCompleted:self.shuffling];
        }
        
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
    
}

@end

